<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>狂神说</title>
    <!--1.导入vue.js axios.js-->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>

<div id="app">
    <todo>
        <!--  v-bind: 可简写为： v-on: 可简写为@   -->
        <todo-title slot="todo-title" v-bind:title="titleData"></todo-title>
        <todo-items slot="todo-items" v-for="(item,index) in todoItems"
                    v-bind:item="item" v-bind:index="index"
                    v-on:remove="removeItems(index)"></todo-items>
                    <!--   v-on:remove="removeItems(index)"> 自定义事件remove     -->
    </todo>
</div>

<script>

    Vue.component("todo",{
        //  \ 换行  slot ：插槽
        template:
            '<div>\
                <slot name="todo-title"></slot>\
                    <ul>\
                        <slot name="todo-items"></slot>\
                    </ul>\
            </div>'
    });

    Vue.component("todo-title",{
        props: ['title'],
        template: '<div>{{title}}</div>'
    });
    Vue.component("todo-items",{
        props: ['item','index'],
        //只能绑定当前组件的方法
        template: '<li>{{index}}----{{item}}  <button @click="remove">删除</button></li>',
        methods: {
            remove: function (index) {
                //调用Vue方法
                //this.$emit(); 自定义事件分发
                this.$emit('remove',index);
            }
        }
    });

    let app = new Vue({
        el: '#app',
        data: {
            titleData: "秦琴 : ",
            todoItems: ['狂神说Java','狂神说前端','狂神说Linux']
        },
        methods: {
            removeItems: function (index) {
                console.log("删除："+this.todoItems[index]+"OK")
                this.todoItems.splice(index,1); //一次删除一个
            }
        }
    });

</script>

</body>
</html>